package com.itheima.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/10 11:57
 * @description：
 */
@RestController
@RequestMapping("/checkitem")
@Api("检查项")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @GetMapping("deleteById/{id}")
    @ApiOperation(value = "删除检查项")
    @PreAuthorize("hasAuthority('del_checkitem')")
    public Result deleteById(@PathVariable("id") Long id){
        return new Result(checkItemService.deleteById(id));
    }

    @PostMapping("save")
    @ApiOperation(value = "添加或修改检查项")
    @PreAuthorize("hasAuthority('add_checkitem')")
    public Result save(@RequestBody CheckItem checkItem){
        return new Result(checkItemService.saveOrUpdate(checkItem));
    }


    @GetMapping("findall")
    @ApiOperation("查询所有")
    public Result findAll(){
        return new Result(checkItemService.findAll());
    }

    /*@PostMapping("findPageByName")
    @ApiOperation("通过名称分页查询")
    public PageResult findPageByName(@RequestBody QueryPageBean pageBean){
        PageResult pageByName = checkItemService.findPageByName(pageBean);
        return pageByName;
    }*/

    @PostMapping("/findByPage")
    @ApiOperation("分页查询所有")
    @PreAuthorize("hasAuthority('search_checkitem')")
    public Result findByPage(@RequestBody QueryPageBean pageBean){
        return new Result(checkItemService.findByPage(pageBean));
    }
}
